<?php

namespace app\index\model;

use think\Model;

class Region extends Model
{
    /**
     * @return Region[]|\think\Collection
     * ljj
     * 获取省级行政区
     */
    public function getReginAttr()
    {
        return $this->field('cri_name')
                    ->limit(34)
                    ->select();
    }

    /**
     * @param $provinceCode
     * @return Region[]|\think\Collection
     * ljj
     * 获取市级行政区
     */
    public function getUrbanAttr($provinceCode)
    {
        return $this->where('cri_parent_code','=',$provinceCode)->where('cri_level','=','2')->field('cri_name')->select();
    }

    /**
     * @param $urbanCode
     * @return Region[]|\think\Collection
     * ljj
     * 获取镇级行政区
     */
    public function getTownAttr($urbanCode)
    {
        return $this
            ->where('cri_parent_code','=',$urbanCode)
            ->field('cri_name')
            ->select();
    }

    public function hotCity()
    {
        return $this->orderRand()->where([['cri_id','>','34'],['cri_id','<','706']])->field('cri_short_name')->limit(8)->select();
    }
}